<?php

namespace app\admin\controller;

use app\admin\model\AdminUser;
use app\BaseController;
use app\Request;

class User extends BaseController
{
    protected $middleware = ['Auth'];

    public function info(Request $request) {
        $params = ['sysUser' => $request->user, 'permissions' => []];
        return result()->success($params);
    }
    public function edit(Request $request)
    {
        $params = $this->request->post(['nickname', 'sex', 'email', 'remark']);
        $params['id'] = $request->user['id'];
        $sql = new AdminUser();
        $sql->update($params);
        return result()->onlySucMsg("修改成功");
    }
    public function updpass(Request $request)
    {
        $params = $this->request->post(['oldPass','password']);
        $sql = new AdminUser();
        $info = $sql->find($request->user['id']);
        if($info['password'] != md5($params['oldPass'])) {
            return  result()->fail("原密码不正确", 500);
        }
        $info->password = md5($params['password']);
        $info->save();
        return result()->onlySucMsg("修改成功");
    }
}